﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using QunYing.Model;
namespace QunYing.BLL
{
    /// <summary>
    /// Employee
    /// </summary>
    public partial class Employee
    {
        private readonly QunYing.DAL.Employee dal = new QunYing.DAL.Employee();
        public Employee()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string 用户名)
        {
            return dal.Exists(用户名);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(QunYing.Model.Employee model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(QunYing.Model.Employee model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string 用户名)
        {

            return dal.Delete(用户名);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string 用户名list)
        {
            return dal.DeleteList(用户名list);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public QunYing.Model.Employee GetModel(string 用户名)
        {

            return dal.GetModel(用户名);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public QunYing.Model.Employee GetModelByCache(string 用户名)
        {

            string CacheKey = "EmployeeModel-" + 用户名;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(用户名);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (QunYing.Model.Employee)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<QunYing.Model.Employee> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<QunYing.Model.Employee> DataTableToList(DataTable dt)
        {
            List<QunYing.Model.Employee> modelList = new List<QunYing.Model.Employee>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                QunYing.Model.Employee model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new QunYing.Model.Employee();
                    if (dt.Rows[n]["用户名"] != null && dt.Rows[n]["用户名"].ToString() != "")
                    {
                        model.用户名 = dt.Rows[n]["用户名"].ToString();
                    }
                    if (dt.Rows[n]["所属经销商"] != null && dt.Rows[n]["所属经销商"].ToString() != "")
                    {
                        model.所属经销商 = dt.Rows[n]["所属经销商"].ToString();
                    }
                    if (dt.Rows[n]["是否启用"] != null && dt.Rows[n]["是否启用"].ToString() != "")
                    {
                        if ((dt.Rows[n]["是否启用"].ToString() == "1") || (dt.Rows[n]["是否启用"].ToString().ToLower() == "true"))
                        {
                            model.是否启用 = true;
                        }
                        else
                        {
                            model.是否启用 = false;
                        }
                    }
                    if (dt.Rows[n]["密码"] != null && dt.Rows[n]["密码"].ToString() != "")
                    {
                        model.密码 = dt.Rows[n]["密码"].ToString();
                    }
                    if (dt.Rows[n]["验证信息"] != null && dt.Rows[n]["验证信息"].ToString() != "")
                    {
                        model.验证信息 = dt.Rows[n]["验证信息"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

